import re
import json
from copy import deepcopy

last_len = 0

class String:
    def output_proc(s, end = ""):
        global last_len
        ch_cnt = len(re.findall(r'[\u4e00-\u9fff]+?', s))
        s_len = len(s) + ch_cnt
        backspace = ' ' * (last_len - s_len)
        last_len = s_len
        s = s + backspace + end
        print("\r" + s, end = "")
    def __get_jsonpath(data, result, path, cur):
        if type(data) is list:
            if 0 == len(data):
                String.__get_jsonpath(cur, result, path, cur)
            for i in range(len(data)):
                String.__get_jsonpath(data[i], result, path + "." + str(i), cur)
        elif type(data) is dict:
            if 0 == len(data):
                String.__get_jsonpath(cur, result, path, cur)
            for i in data:
                String.__get_jsonpath(data[i], result, path + "." + i, cur)
        else: result.append(path)
    def get_json_path(data):
        result = []
        String.__get_jsonpath(data, result, "$", "")
        return result
    def format_json_str(data_src):
        data = deepcopy(data_src)
        if type(data) is str:
            try: data = json.loads(data)
            except: return data
        if type(data) is dict:
            for i in data:
                data[i] = String.format_json_str(data[i])
        if type(data) is list:
            for i in range(len(data)):
                data[i] = String.format_json_str(data[i])
        return data

